package com.ssc.portal.www.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.ssc.manager.trading.dto.BetDto;
import com.ssc.portal.common.constant.SystemConstant;
import com.ssc.portal.www.dao.IUserAssetDao;
import com.ssc.portal.www.ice.ClientIntegration;
import com.ssc.portal.www.service.IInvestBetService;

@Service
public class InvestBetService implements IInvestBetService {

	@Autowired
	private IUserAssetDao userAssetDao;
	
	@Autowired
	private ClientIntegration clientIntegration;
	
	@Override
	public String investBet(BetDto bet) {
		if(!haveMoney(bet)){
			return SystemConstant.ADD_BET_NOTMONEY;
		}
		clientIntegration.betting(JSON.toJSONString(bet));
		return SystemConstant.ADD_BET_RSUCCESS;
	}
	
	/**
	 * 验证用户的余额
	 * @param bet
	 * @return
	 */
	private boolean haveMoney(BetDto bet){
		Double userMoney = userAssetDao.findUserMoney(bet.getUserid());
		if(userMoney.compareTo(bet.getSumMoney())<0)
			return false;
		return true;
	}

}
